define(['jquery', 'bootstrap', 'backend', 'addtabs', 'table', 'echarts', 'echarts-theme', 'template'], function ($, undefined, Backend, Datatable, Table, Echarts, undefined, Template) {

    var Controller = {
        index: function () {

            var list2 = [];
            $.ajax({
                url:"feedback/feedback/index",
                async:false,
                dataType:'json',
                type:'post',
                success:function(data){
                    if(data.code == 1){
                        for(var i = 0 ; i < data.data.length; i++){

                            switch ( data.data[i].feedback ){
                                case 0:
                                    feedback = "暂无反馈";
                                break;
                                case 1:
                                    feedback = "电话拒接";
                                break;
                                case 2:
                                    feedback = "电话空号或停机";
                                break;
                                case 3:
                                    feedback = "客户不需要";
                                break;
                                case 4:
                                    feedback = "客户有意向";
                                break;
                                case 5:
                                    feedback = "其他";
                                break;
                            }

                            list2.push( {name:feedback,value:data.data[i].total} );
                        }
                    }
                }
            });

            console.log(list2);
            var myChart = Echarts.init(document.getElementById('echart'),'walden');
/*
            option = {
                backgroundColor: '#2c343c',

                title: {
                    text: '问题反馈',
                    left: 'center',
                    top: 20,
                    textStyle: {
                        color: '#ccc'
                    }
                },
                legend: {
                    orient: 'vertical',
                    x: 'left',
                    data:["暂无反馈",'客户不需要','客户有意向','电话空号或停机','电话拒接','其他']
                },
                tooltip : {
                    trigger: 'item',
                    formatter: "{a} <br/>{b} : {c} ({d}%)"
                },

                visualMap: {
                    show: false,
                    min: 80,
                    max: 600,
                    inRange: {
                        // colorLightness: [0, 1]
                    }
                },
                series : [
                    {
                        name:'访问来源',
                        type:'pie',
                        // radius : '55%',
                        // center: ['50%', '50%'],
                        data:list2.sort(function (a, b) { return a.value - b.value; }),
                        // roseType: 'radius',
                        label: {
                            normal: {
                                // textStyle: {
                                //     color: 'rgba(255, 255, 255, 0.3)'
                                // }
                                show: false,
                                position: 'center'
                            }
                        },
                        labelLine: {
                            normal: {
                                // lineStyle: {
                                //     color: 'rgba(255, 255, 255, 0.3)'
                                // },
                                // smooth: 0.2,
                                // length: 10,
                                // length2: 20
                                show:false,
                            }
                        },
                        itemStyle: {
                            normal: {
                                color: '#c23531',
                                shadowBlur: 200,
                                shadowColor: 'rgba(0, 0, 0, 0.5)'
                            }
                        },

                        animationType: 'scale',
                        animationEasing: 'elasticOut',
                        animationDelay: function (idx) {
                            return Math.random() * 200;
                        }
                    }
                ]
            };*/

            option = {
                title: {
                    text: '问题反馈',
                    left: 'center',
                    top: 20,
                    textStyle: {
                        color: '#ccc'
                    }
                },
                legend: {
                    orient: 'vertical',
                    x: 'left',
                    data:["暂无反馈",'客户不需要','客户有意向','电话空号或停机','电话拒接','其他']
                },

                tooltip : {
                    trigger: 'item',
                    formatter: "{a} <br/>{b} : {c} ({d}%)"
                },

                toolbox: {
                    show : true,
                    feature : {
                        mark : {show: true},
                        dataView : {show: true, readOnly: false},
                        magicType : {
                            show: true,
                            type: ['pie', 'funnel']
                        },
                        restore : {show: true},
                        saveAsImage : {show: true}
                    }
                },
                calculable : true,
                series : [
                    {
                        name:'反馈信息',
                        type:'pie',
                        radius : [30, 110],
                        center: ['50%', '50%'],
                        roseType : 'area',
                        data:list2
                    }
                ]
            };

         /*   option = {
                tooltip: {
                    trigger: 'item',
                    formatter: "{a} <br/>{b}: {c} ({d}%)"
                },
                legend: {
                    orient: 'vertical',
                    x: 'left',
                    data:["暂无反馈",'客户不需要','客户有意向','电话空号或停机','电话拒接','其他']
                },
                series: [
                    {
                        name:'访问来源',
                        type:'pie',
                        radius: ['50%', '70%'],
                        avoidLabelOverlap: false,
                        label: {
                            normal: {
                                show: false,
                                position: 'center'
                            },
                            emphasis: {
                                show: true,
                                textStyle: {
                                    fontSize: '30',
                                    fontWeight: 'bold'
                                }
                            }
                        },
                        labelLine: {
                            normal: {
                                show: false
                            }
                        },
                        data:list2.sort(function (a, b) { return a.value - b.value; })
                    }
                ]
            };*/

            myChart.setOption(option);


            /*  // 初始化表格参数配置
              Table.api.init({
                  extend: {
                      index_url: 'feedback/feedback/index',
                  }
              });
              var table = $("#table");

              // 初始化表格
              table.bootstrapTable({
                  url: $.fn.bootstrapTable.defaults.extend.index_url,
                  pk: 'id',
                  sortName: 'user.id',
                  columns: [
                      [
                          {checkbox: true},
                          {field: 'id', title: __('Id'), sortable: true},
                          {field: 'username', title: __('平台名称'), operate: 'LIKE'},
                          {field: 'operate', title: __('Operate'), table: table,
                              events: Table.api.events.operate,
                              buttons: [
                                  {
                                      name: 'addgoldcoin',
                                      title: __('弹出窗口打开'),
                                      classname: 'btn btn-xs btn-primary btn-dialog',
                                      icon: 'fa fa-list',
                                      url: 'user/pt/details'
                                  }
                              ],
                              formatter: Table.api.formatter.operate,

                          }
                      ]
                  ]
              });

              // 为表格绑定事件
              Table.api.bindevent(table);*/


        },
    };
    return Controller;
});